package org.i1510.common.utils;


import org.i1510.common.utils.web.ResultMapper;
import org.slf4j.Logger;

public class LogTools {
	private Logger logger;
	private String ip;
	private String action;
	private String mobilenum;
	private String mac;
	private String msg;
	private String userid;
	
	
	
	public String getUserid() {
		return userid;
	}
	public void setUserid(String userid) {
		this.userid = userid;
	}
	public Logger getLogger() {
		return logger;
	}
	public void setLogger(Logger logger) {
		this.logger = logger;
	}
	public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	public String getAction() {
		return action;
	}
	public void setAction(String action) {
		this.action = action;
	}
	public String getMobilenum() {
		return mobilenum;
	}
	public void setMobilenum(String mobilenum) {
		this.mobilenum = mobilenum;
	}
	public String getMac() {
		return mac;
	}
	public void setMac(String mac) {
		this.mac = mac;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public LogTools(Logger logger , String ip , String action , String mobilenum , String mac , String msg , String userid) {
		this.logger = logger;
		this.ip = ip;
		this.action = action;
		this.mobilenum = mobilenum;
		this.mac = mac;
		this.msg = msg;
		this.userid = userid;
	}
	
	
	public String error(int code , String paramname) {
		logger.error(ip + "|" + action.toUpperCase() + "|" + mobilenum + "|"+ mac +"|错误编码：" + code + "|描述：缺少" + paramname + "参数");
		ResultMapper mapper = ResultMapper.generateFailure("网络超时，请稍后尝试! -" + code);
		return mapper.toJson();
	}
	
	public String error(String message) {
		logger.error(ip + "|" + action.toUpperCase() + "|" + mobilenum + "|"+ mac + "|" + message);
		ResultMapper mapper = ResultMapper.generateFailure(message);
		return mapper.toJson();
	}
	
	public void info(String content) {
		logger.info(ip + "|" + action.toUpperCase() + "|" + mobilenum + "|"+ mac + "|" + userid + "|" + content);
	}
}
